<?php
//echo md5("Lillehammer2010");die;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of system_controller
 *
 * @author phamhphuc
 */
class system_controller_admin extends system_controller {
    
    public function __construct($config) {              
        $this->config = $config;        
        if(isset($config['default_action'])) {
            $this->action = $config['default_action'];
        }
        $this->view = new system_view();        
        $this->session = new system_session($config, "referer_admin_");
        $this->db = new system_db($config);               
        
        $this->_setupData();        
        $this->init();
    } 
    
    public function init(){
        parent::init();
        $this->view->layoutUrl = "../../../admin/templates/{$this->config['template_name']}/layouts/";
        
        // check for login
        if(!$this->session->user){
            if(isset($_REQUEST['action'])) {
                $this->action = $_REQUEST['action'];
            }
            if($this->action != "login") {               
                header("location: ?action=login");
            }
        }
    }
    
    public function getTemplateDir(){
        if($this->config['template_name']) {
            return "../../../admin/templates/{$this->config['template_name']}/";
        }
        return "";
    }
    
    public function getTemplateURL(){
        if($this->config['template_name']) {
            return "../../../admin/templates/{$this->config['template_name']}/";
        }
        return "";
    }
    
    private function _setupData()
    {                
        $this->config['template_dir'] = $this->getTemplateDir();
        $this->config['template_url'] = $this->getTemplateURL();
    }
}

?>
